<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Index_Test extends Controller_Index_Base
{
    public function before()
    {
        //die('dsds');
    }
    
    public function action_test1()
    {
        $product = ORM::factory('product', 157869);
        Model_ProductParser_FromShop_Wildberries::instance()->parse($product);  
    }
    
    public function action_test2()
    {
        set_time_limit(0);
        
        /*
        515     Quelle          цвет
        1001    Lamoda          цвет, материал, сезон
        1186    Proskater       цвет
        1326    TOPBRANDS       цвет, материал
        1477    ShopTime        -
        1757    BUTIK           цвет
        2775    MEXX            -
        2777    TomTailor       -
        3761    SHOWROOMS       материал
        4102    Wildberries     цвет, материал (состав), сезон, стиль
        */
        
        $params = array();
        $desc   = array();
        
        $products = ORM::factory('product')
                        ->where('shop_id', '=', 1001)
                        ->find_all();
        foreach ($products as $product) {
            if ($product->params) {
                foreach (json_decode($product->params, true) as $name => $value) {
                    $value = trim($value);
                    $name  = mb_strtolower($name);
                    if (!isset($params[$name])) {
                        $params[$name] = array();       
                    }
                    $values = explode(',', $value);
                    foreach ($values as $value) {
                        $value = trim($value);
                        if (!isset($params[$name][$value])) {
                            $params[$name][$value] = 1;    
                        }
                        $params[$name][$value]++; 
                    }                    
                }
            }
            if ($product->description) {
                $description = explode(' ', $product->description);
                foreach ($description as $item) {
                    $item = trim($item);
                    if (!isset($desc[$item])) {
                        $desc[$item] = 1;    
                    }
                    $desc[$item]++;       
                }
            }         
        }
        foreach ($params as &$group) {
            arsort($group);    
        }
        arsort($desc);
        
        echo '<pre>';
        print_r($params);
        /*print_r($params['состав']);
        
        $composition = array();
        $_composition = $params['состав'];
        foreach ($_composition as $item => $count) {
            $parts = explode(' ', $item);
            if (strstr($item, '%') !== false) {
                unset($parts[count($parts)-1]);        
            } 
            $item = implode(' ', $parts);
            if (!isset($composition[$item])) {
                $composition[$item] = 0;    
            }
            $composition[$item] += $count;   
        }
        print_r($composition);    */
        
        //print_r($desc);
    } 
    
    public function action_test3()
    {
        die();
        set_time_limit(0);
        
        function get_parents($category, &$cats) {
            $text = array();
            $text[] = mb_strtolower($category->name);
            $cat = $cats[$category->id];
            while ($cat->parent_id != 0) {
                $cat = $cats[$cat->parent_id];
                $text[] = mb_strtolower($cat->name);
            }
            return implode(' - ', $text);    
        }  
        
        $categories = ORM::factory('category')->find_all();
        $categories = Model_Main::process_array($categories); 
        
        foreach ($categories as $category) {
            $text = get_parents($category, $categories); 
            
            $category->nominative_form = $text; 
            $category->accusative_form = $text;
            $category->save();  
        }
    }
    
    public function action_test4()
    {
        die();
        set_time_limit(0);
        
        $products = ORM::factory('product')
                ->where('shop_id', '=', 1001)
                //->where('is_parsed', '=', 0)
                ->limit(1000)
                ->find_all();
        $n = 0;
        foreach ($products as $product) {
            $product->process_params(); 
        }
    }
    
    public function action_test5()
    {
        die();
        $lines = file('./1.txt');
        
        $composition = array();
        foreach ($lines as $item) {
            list($item, $count) = explode(' => ', $item);
            $item = str_replace(array('[', ']'), array('', ''), $item);
            $parts = explode(' ', $item);
            if (strstr($item, '%') !== false) {
                unset($parts[count($parts)-1]);        
            } 
            $item = implode(' ', $parts);
            if (!isset($composition[$item])) {
                $composition[$item] = 0;    
            }
            $composition[$item] += $count;   
        }
        arsort($composition);
        echo '<pre>';
        print_r($composition);
    }
    
    public function action_test6()
    {
        die();
        set_time_limit(0); 
        
        $brands = ORM::factory('brand')->find_all();
        foreach ($brands as $brand) {
            $brand_url  = Model_Main::translit($brand->name);
            $brand_url  = str_replace('-amp-', '-and-', $brand_url);
            
            $brand->url = $brand_url;
            $brand->save();    
        }
    }
    
    public function action_test7()
    {
        //die();
        foreach (Model_Season::get_all_seasons() as $item) {
            echo $item['url'].' - '.Model_Main::translit($item['name']).'<br />';   
        }
    }
    
    public function action_test8()
    {
        $ids = array(
       
        );
        
        /*$url = 'http://www.wildberries.ru/catalog/102/women.aspx';
        $data = Model_ProductParser_Abstract::_get_source_code($url);
        print_r($data);
        die();   */
        
        die();
        set_time_limit(0);
        
        $pages = array('women.aspx', 'men.aspx', 'page.aspx');
        
        $n = 0;
        foreach ($ids as $id) {
            foreach ($pages as $page) {
                $url = 'http://www.wildberries.ru/catalog/'.$id.'/'.$page;
                $data = Model_ProductParser_Abstract::_get_source_code($url);
                usleep(500000); 
                if (strstr($data, 'HTTP/1.1 200 OK') !== false) {
                    echo $url.'<br />'; 
                    $n++;
                    break;   
                }   
            }    
        }
        
        echo count($ids).' - '.$n;                                             
    }
    
    public function action_test9()
    {
        die();
        set_time_limit(0);
        $data = DB::select()
                    ->from('product_data')
                    ->where('params', 'IS NOT', NULL)
                    ->where('clean_params', 'IS', NULL)
                    ->limit(100000)
                    ->execute()
                    ->as_array();
                    
        foreach ($data as $item) {
            $clean_params = Model_Product::get_clean_params($item['params']); 
            
            DB::update('product_data')
                ->set(array('clean_params' => $clean_params))
                ->where('product_id', '=', $item['product_id'])
                ->execute();   
        }
    }
    
    public function action_test10()
    {
        set_time_limit(0);
        //$keys = file('./keys/1.txt');
        $keys = array(
            
        );
        
        $n = 1;
        $null_count = 0;
        echo '<table>';
        foreach ($keys as $key => $title) {
            $key = trim($key);
            $count_products = ORM::factory('product')->search($key, 60, true);
            if ($count_products == 0) {
                continue;    
            }
            echo "<tr>";
            echo "<td>{$n}</td>";
            echo "<td>{$key}</td>";
            echo "<td>{$title}</td>";
            echo "<td>{$count_products}</td>"; 
             echo "</tr>";
            //echo '#'.$n.' - '.$key.' - '.count($products).'<br />'; 
            if ($count_products == 0) {
                $null_count++;    
            }
            $n++;   
        }
        echo '</table>';
        echo 'null - '.$null_count;
                     
    }
    
    public function action_test11()
    {
        function translit($str) {
            $tr = array(
                'a' => 'а',
                'b' => 'б',
                'c' => 'к',
                'd' => 'д',
                'e' => 'е',
                'f' => 'ф',
                'g' => 'г',
                'h' => 'х',
                'i' => 'и',
                'j' => 'ж',
                'k' => 'к',
                'l' => 'л',
                'm' => 'м',
                'n' => 'н',
                'o' => 'о',
                'p' => 'п',
                'q' => 'к',
                'r' => 'р',
                's' => 'с',
                't' => 'т',
                'u' => 'у',
                'v' => 'в',
                'w' => 'в',
                'x' => 'кс',
                'y' => 'и',
                'z' => 'з',
            );
            
            /*$result = '';
            for ($i = 0; $i < mb_strlen($str); $i++) {
                if (isset($tr[$str[$i]])) {
                    $result .= $tr[$str[$i]];    
                }
            } */
            
            $result = strtr($str, $tr); 
            $result = iconv('utf-8', 'cp1251', $result); 
            //$result = iconv('cp1251', 'utf-8', $result);   
            //if (preg_match('/[^A-Za-z0-9_\-]/', $result)) {
            //    $result = preg_replace('/[^A-Za-z0-9_\-]/', '', $result);
            //}    
            $result = str_replace('  ', ' ', $result);    
            return strtolower($result);
        }
        
        //die(translit('queen'));
        
        $brands = ORM::factory('brand')
                    ->where('synonyms', 'IS', NULL)
                    ->find_all();
        foreach ($brands as $brand) {
            $synonyms = array();
            $name     = str_replace('-', ' ', $brand->url);
            $synonyms[] = $name;
            $synonyms[] = translit($name); 
            
            //$brand->synonyms = implode(', ', $synonyms);
            //$brand->save();
            echo "UPDATE brands SET synonyms = '".implode(', ', $synonyms)."' WHERE id = {$brand->id};<br />";
            //echo $brand->name.' - ';
            //print_r($synonyms);
            //echo '<br />';  
        }    
    }
    
    public function action_test12()
    {
        $cats = array(
            3400000,
            3600000,
            3700000,
            4200000,
            4500000,
            4700000,
            4400000,
            141,
            411,
            140,
            27863,
            422,
            176,
            68,
            358,
            70,
            71,
            177,
            25234,
            720,
            79,
            340,
            338,
            339,
            3422,
            78,
            77,
            296,
            3418,
            414,
            95,
            3419,
            96,
            3417,
            94,
            231,
            275,
            29225,
            345,
            346,
            342,
            343,
            112,
            236,
            347,
            113,
            110,
            344,
            111,
            25268,
            25266,
            25267,
            246,
            192,
            129,
            404,
            128,
            8948,
            127,
            130,
            190,
            8947,
            224,
            147,
            3410,
            25260,
            215,
            398,
            107,
            407,
            397,
            3412,
            160,
            216,
            174,
            199,
            3407,
            3413,
            3414,
            417,
            3406,
            3411,
            8256,
            3408,
            3405,
            105,
            3409,
            106,
            159,
            25255,
            198,
            25254,
            25263,
            421,
            175,
        );
        set_time_limit(0);
        
        foreach ($cats as $cat) {
            $products = ORM::factory('product')
                    ->where('original_category_id', '=', $cat)
                    ->where('shop_id', '=', 5057)
                    ->limit(30)
                    ->order_by(DB::expr('RAND()'))
                    ->find_all();
            
            echo '<h2>'.$cat.'</h2>';
            foreach ($products as $product) {
                echo '<a href="http://stylemay.ru/product/'.$product->id.'-ds"><img src="'.$product->picture.'" style="margin: 5px; width: 150px;" /></a>';    
            }
            echo '<br /><br />';    
        }
    }
    
    public function action_test13()
    {
        set_time_limit(0);
        /*$products = ORM::factory('product')
                    //->where('id', '>=', 2062157)->limit(10)
                    //->offset(10000)
                    ->limit(100000)
                    ->order_by('id', 'DESC')
                    ->find_all(); 
        
        $filter = array();            
        foreach ($products as $product) {
            if (isset($filter[$product->url])) {
                continue;    
            }
            
            $copies = ORM::factory('product')
                    ->where('url', '=', $product->url)
                    ->find_all()
                    ->as_array();                
            $filter[$product->url] = 1;
                
            echo $product->id.'<br />'; 
            $ids = array(); 
            foreach ($copies as $copy) {
                if ($product->id == $copy->id) {
                    continue;
                }
                echo '--- '.$copy->id.'<br />';
                $ids[] = $copy->id;   
            } 
            if (count($ids)) { 
                DB::delete('products')
                        ->where('id', 'IN', $ids)
                        ->execute();
            }
        }  */
        die();
        $ids = DB::query(Database::SELECT, "SELECT id FROM products AS p WHERE EXISTS (SELECT id FROM products WHERE url = p.url AND id != p.id) LIMIT 10000")
                ->execute()->as_array(); 
        if (count($ids)) { 
            DB::delete('products')
                    ->where('id', 'IN', $ids)
                    ->execute();
        }       
        
    }
    
    public function action_test14()
    {
        set_time_limit(0);
        
        $cats = array(
            'обувь',
            'одежда',
            'ботинки',
            'сапоги',
            'кроссовки',
            'куртки',
            'платья',
            'пуховики',
            'сумки',
            'кеды',
            'туфли',
            'костюмы',
            'джинсы',
            'часы',
            'рюкзаки',
            'брюки',
            'перчатки',
            'пальто',
            'комплекты',
            'бутсы',
            'шапки',
            'комбинезоны',
            'футболки',
            'сабо',
            'штаны',
            'постельное белье',
            'нижнее белье',
            'белье',
            'ботильоны',
            'куклы',
            'жилетки',
            'унты',
            'трусы',
            'поло',
            'валенки',
            'полусапоги',
            'парки',
            'ботфорты',
            'кошельки',
            'шорты',
            'зонты',
            'сковороды',
            'блузки',
            'блузы',
            'коляски',
            'борцовки',
            'термобелье',
            'чайники',
            'духи',
            'туалетная вода',
            'шиповки',
            'дутики',
            'толстовки',
            'тушь',
            'рубашки',
            'коврики',
            'резиновые сапоги',
            'конструкторы',
            'пижамы',
            'ремни',
            'столики',
            'шлепанцы',
            'трусики',
            'экипировки',
            'коляски',
            'кофты',
            'кардиганы',
            'твинсеты',
            'пуловеры',
            'джемперы',
            'свитеры',
            'свитшоты',
            'олимпийки',
            'топы',
            'жилеты',
            'пиджаки',
            'жакеты',
            'юбки',
            'сарафаны',
            'плащи',
            'тренчкоты',
            'пантолеты',
            'угги',
            'сланцы',
            'полусапоги',
            'мокасины',
            'луноходы',
            'галоши',
            'босоножки',
            'балетки',
            'очки',
            'варежки',
            'шарфы',
            'шали',
            'зеркальца',
            'клатчи',
            'портфели',
            'косметички',
            'бейсболки',
            'бриджи',
            'водолазки',
            'галстуки',
            'ветровки',
        );
        
        $brands = array(
            'nike    -    найк',
            'adidas    -    адидас',
            'salomon    -    саломон(соломон)',
            'tervolina    -    терволина',
            'vis a vis    -    виз а ви(вис а вис)',
            'puma    -    пума',
            'columbia    -    коламбия',
            'versace    -    версаче(версачи)',
            'timberland    -    тимберленд(тимберленды)',
            'savage    -    саваж',
            'mango    -    манго',
            'puma    -    пума',
            'reima    -    рейма',
            'kerry',
            'tom farr    -    том фар(том фарр)',
            'tom tailor    -    том тейлор(том тэйлор)',
            'reebok    -    рибок',
            'burton',
            'papaya',
            'the north face(north face)',
            'sela    -    села',
            'ralf ringer    -    ральф рингер',
            'guess',
            'rieker',
            'vans',
            'riker    -    рикер',
            'asics',
            'salamander    -    саламандер',
            'caterpillar',
            'ecco    -    экко',
            'tempo kids',
            'lider kids',
            'new balance',
            'calvin klein',
            'g star raw',
            'buffalo',
            'creative recreation',
            'diesel    -    дизель',
            'la vida rica',
            'la perla',
            'gucci',
            'pompa',
            'pierre cardin',
            'odri',
            's oliver',
            'top secret    -    топ сикрет(топ секрет)',
            'vienetta secret',
            'pepe jeans',
            'salsa jeans',
            'camelot    -    камелот',
            'wenger swissgear',
            'vitacci    -    витачи',
            'just cavalli',
            'roberto cavalli    -    роберто кавалли',
            'winx',
            'el tempo',
            'deux par deux',
            'keddo',
            'viking    -    викинг',
            'caprice',
            'new balance',
            'gerzedo',
            'мульти пульти',
            'crocs',
            'mizuno',
            'max factor',
            'eleganzza',
            'christian dior',
            'jadore dior',
            'dino ricci',
            'vitesse',
            'cat',
            'patrol',
            'samsonite',
            'umbro',
            'stayer',
            'sport vision',
            'chicco',
            'grand style    -    гранд стиль(грант стиль)',
            'classic style',
            'maxi cosi',
            'just roxy',
            'just couture',
            'river island',
            'skechers',
            'lego',
            'dc shoes',
            'dc',
            'givenchy',
            'wrangler    -    вранглер',
            'basic',
            'шалуны',
            'dupont',
            'togas',
            'hermes',
            'finn flare',
            'converse',
            'nova tour',
            'gezatone',
            'trespass',
            'palio    -    палио',
            'gusti',
            'tamaris',
            'david jones    -    дэвид джонс',
            'jack jones',
            'maison scotch',
            'fred perry',
            'baon    -    баон',
            'lancome',
            'michael kors',
            'salewa',
            'lee cooper',
            'cooper',
            'lee daren',
            'lee',
            'bogner',
            'el tempo',
            'vero moda    -    веро мода',
            'armani',
            'luhta',
            'llorens',
            'jessica simpson',
            'ugg',
            'pull and bear',
            'rukka',
            'тамарис',
            'anastasia beverly hills',
            'calipso',
            'remix',
            'marco tozzi',
            'ash',
            'sinta gamma',
            'sinta',
            'gf ferre',
            'mexx',
            'djeco',
            'pelican',
            'silverlit',
            'roxy',
            'deux par deux',
            'elie saab',
            'intex',
            'avent',
            'max factor',
            'marc',
            'leo guy',
            'leo ventoni',
            'mattel',
            'gulliver',
            'brio',
            'cartier',
            'paolo conte',
            'la perla',
            'incanto',
            'incity    -    инсити',
            'lawine',
            'icepeak',
            'winzor',
            'hasbro',
            'speedo',
            'spur',
            'geox',
            'demar',
            'chopard',
            'pajar',
            'hi tec',
            'best mountain',
            'best connection',
            'hugo boss',
            'gas',
            'naf naf',
            'sabotage    -    саботаж',
            'baldinini    -    балдинини',
            'clarks',
            'ben sherman',
            'bright starts',
            'comma',
            'merries',
            'gant',
            'prada',
            'kuoma    -    куома',
            'zest',
            'knirps',
            'nano',
            'dakine',
            'vdp',
            'esprit',
            'stets',
            'de salitto',
            'versace',
            'marco tozzi',
            'hogl',
            'pepe jeans',
            'ravensburger',
            'rouge bunny rouge',
            'oldos    -    олдос',
            'coccinelle',
            'deuter',
            'ralph lauren',
            'pola',
            'lonsdale',
            'jana',
            'dkny jeans',
            'charuel',
            'merrell',
            'people',
            'valentino',
            'schleich',
            'mascotte',
            'sisley',
            'crosby',
            'emporio armani',
            'primo emporio',
            'john varvatos',
            'john galliano',
            'hugo boss',
            'helena rubinstein',
            'moxie',
            'red fox',
            'fox',
            'clementoni',
            'cacharel',
            'cerruti 1881',
            'parker',
            'sacha fabiani',
            'fabiani',
            'inglesina',
            'grand gudini',
            'apart',
            'desigual',
            'sun city',
            'evita',
            'snowimage',
            'betsy',
            'strellson',
            'rinascimento',
            'lacoste',
            'broadway',
            'alexander hotto',
            'alexander mcqueen',
            'canpol babies',
            'tiny love',
            'welly',
            'oldos',
            'nine west',
            'selected',
            'sorel',
            'guahoo',
            'lego    -    лего',
            'choupette',
            'romanoff    -    романофф',
            'provocante    -    провоканте',
            'trailhead',
            'hello kitty',
            'ice watch',
            'bright starts',
            'bench',
            'moony',
            'burlesque',
            'domani',
            'iguana',
            'kiddieland',
            'laete',
            'fossil',
            'next',
            'paolo conte',
            'collistar',
            'in wear',
            'lego wear',
            'osiris',
            'goon',
            'vagabond    -    вагабонд',
            'gezanne',
            'anta',
            'hays',
            'laura scott',
            'laura bruno',
            'braccialini',
            'dr martens',
            'playtoday',
            'fisher price',
            'scotch soda',
            'ara gore tex',
            'rukka gore tex',
            'viking gore tex',
            'playmobil',
            'thor steinar',
            'milavitsa',
            'biotherm',
            'addicted',
            'vienetta secret',
            'geoby joss',
            'betty barclay',
            'betty boop',
            'geoby joss',
            'equal',
            'marc o polo(marco polo)',
            'kipling',
            'goddiva plus',
            'levis',
            'french connection',
            'best connection',
            'bronx',
            'pinko',
            'motivi',
            'rider',
            'carters',
            'otto',
            'svetski',
            'ga de',
            'didriksons',
            'britax',
            'ziener',
            'trussardi',
            'bass',
            'nania',
            'woolrich',
            'corso como',
            'odlo',
            'provocante',
            'hauck',
            'dior homme',
            'froggy',
            'sneaky steve',
            'steve madden',
            'saucony',
            'napapijri',
        );
        
        die();
        
        $f = fopen('brand_keys.txt', 'w');
        
        /*foreach ($brands as $name) {
            foreach ($cats as $cat) {
                $query = $cat.' '.$name;
                
                $tmp_title = explode(' ', $name);
                foreach ($tmp_title as &$part) {
                    $part = Model_Main::ucfirst_utf8($part);       
                }
                $title = Model_Main::ucfirst_utf8($cat).' '.implode(' ', $tmp_title);
                $count_products = ORM::factory('product')->search($query, null, true);
                if ($count_products) {
                    fputs($f, $query."\t\t".$title."\r\n");  
                }    
            }    
        }    */
        
        foreach ($brands as $brand) {
            $names = array();
            $parts = explode("    -    ", $brand);
            foreach ($parts as $part) {
                $tmp_syns = Model_ReviewParser_Abstract::_cut_str('(', ')', $part);
                $syns     = explode(',', $tmp_syns);
                $names[] = $part;
                if (count($syns)) {
                    foreach ($syns as $syn) {
                        if (trim($syn)) {
                            $names[] = trim($syn);   
                        }    
                    }    
                }    
            }   
            
            foreach ($names as $name) {    
                foreach ($cats as $cat) {
                    $query = $cat.' '.$name;
                    
                    $tmp_title = explode(' ', $name);
                    foreach ($tmp_title as &$part) {
                        $part = Model_Main::ucfirst_utf8($part);       
                    }
                    $title = Model_Main::ucfirst_utf8($cat).' '.implode(' ', $tmp_title);
                    
                    $count_products = ORM::factory('product')->search($query, null, true);
                    if ($count_products) {
                        fputs($f, $query."\t\t".$title."\t\t".$cat."\t\t".$names[0]."\r\n");  
                    }    
                }
                /*$count_products = ORM::factory('product')->search($name, null, true);
                if ($count_products) { 
                    echo $name.'<br />';
                } */ 
            }
        }    
        
        
        /*$brands = ORM::factory('brand')
                    ->offset(0)
                    ->limit(100)
                    ->find_all();
        foreach ($brands as $brand) {
            $names = explode(',', $brand->synonyms);
            foreach ($names as $name) {
                $name = trim($name);
                foreach ($cats as $cat) {
                    $query = $cat.' '.$name;
                    
                    $tmp_title = explode(' ', $name);
                    foreach ($tmp_title as &$part) {
                        $part = Model_Main::ucfirst_utf8($part);       
                    }
                    $title = Model_Main::ucfirst_utf8($cat).' '.implode(' ', $tmp_title);
                    $count_products = ORM::factory('product')->search($query, null, true);
                    if ($count_products) {
                        fputs($f, $query."\t\t".$title."\t\t".$count_products."\r\n");  
                    }    
                }    
            } 
        } */
        
    }
    
    public function action_test15()
    {
        die();
        set_time_limit(0);
        
        $cats = DB::select()
                    ->from('categories')
                    //->where('nominative_form', 'LIKE', DB::expr("'%одежда%'"))
                    ->where('nominative_form', 'LIKE', DB::expr("'%обувь%'"))
                    ->where('parent_id', '!=', 0)
                    ->execute()
                    ->as_array();
                    
        foreach ($cats as $cat) {
            $ids = array();            
            if ($cat['childs']) {
                $ids = explode(',', $cat['childs']);    
            }
            $ids[] = $cat['id'];
            
            DB::update('categories')
                ->set(array('type' => 'обувь'))
                ->where('id', 'IN', $ids)
                ->execute();   
        }
    }
    
    public function action_test16()
    {
        $subids = array(
            'yd1_271_m_s_1749906',
'yd1_271_m_s_1888595',
'yd1_271_m_s_325220',
'yd1_271_m_s_531932',
'yd1_271_m_s_970841',
'yd1_641_m_s',
'yd1_641_m_s_436726',
'yd1_641_m_s_438623',
'yd1_749_m_s_1604893',
'yd1_749_m_s_2344109',
'yd1_86_m_s_2355786',
'yd2_1034_r_s_241291',
'yd2_1034_r_s_367871',
'yd2_165_r_s_1614465',
'yd2_165_r_s_1742107',
'yd2_165_r_s_273459',
'yd2_165_r_s_309066',
'yd2_165_r_s_322493',
'yd2_165_r_s_356816',
'yd2_165_r_s_412188',
'yd2_242_m_s_2323524',
'yd2_254_m_s_434015',
'yd2_274_r_s_1727658',
'yd2_2_r_s_2368577',
'yd2_2_r_s_2409445',
'yd2_621_r_s_2312432',
'yd2_621_r_s_2365773',
'yd2_621_r_s_2411610',
'yd2_622_r_s_2335126',
'yd2_622_r_s_2362988',
'yd2_63_r_s_1875312',
'yd2_642_m_s_2316841',
'yd2_642_m_s_2330038',
'yd2_868_m_s_1856890',
'yd2_868_m_s_1893445',
'yd2_868_m_s_1893490',
'yd2_868_m_s_2344292',
'yd2_868_m_s_2364676',
'yd2_868_m_s_2369151',
'yd2_868_m_s_2369157',
'yd2_868_m_s_2382800',
'yd3_152_r_s_367819',
'yd3_350_m_s_180990',
'yd3_350_m_s_296847',
'yd3_3_r_s_774589',
'yd3_608_m_s_1200713',
'yd3_608_m_s_1725689',
'yd3_608_m_s_1726510',
'yd3_8_r_s_412742',
        );
        
        $result = array();
        foreach ($subids as $subid) {
            $tmp = explode('_', $subid);
            $clean = $tmp[0].'_'.$tmp[1].'_'.$tmp[2];
            if (!isset($result[$clean])) {
                $result[$clean] = 0;    
            }  
            $result[$clean]++; 
        }
        
        echo count($result);
        echo '<pre>';
        print_r($result);
    }
    
    public function action_test17()
    {
        echo file_get_contents('http://www.dressterra.ru/go/shop/?page=141685911227');
        die();
        
        /*die();
        set_time_limit(0);
        Model_Sitemap::generate_sitemap(); */
    }
    
    public function action_test18()
    {
        set_time_limit(0);
        Model_ProductParser_Ebay::instance()->parse();
    }
    
    public function action_test19()
    {
        //die();
        set_time_limit(0);    
        $categories = ORM::factory('category')->find_all();
        foreach ($categories as $category) {
            $category->url = Model_Main::translit($category->nominative_form);
            $category->save();        
        }
    }
} 
